#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 10;
vector<int> cnt[N];
map<int, int> mp;
int a[N], v[N], st[N], n, m, L, V, p[N],cat[N],ans=0;
struct node
{
    int w, id;
} s[N];
bool cmp(node a,node b){
    return a.w>b.w;
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while (t--)
    {
        cin >> n >> m >> L >> V;
        int sum = n;
        for (int i = 1; i <= m; i++)
        {
            s[i].id = i;
        }
        for (int i = 1; i <= n; i++)
        {
            cin >> st[i] >> v[i] >> a[i];
        }
        for (int i = 1; i <= m; i++)
        {
            int pos;
            cin >> pos;
            p[i] = pos;
            mp[pos] = i;
        }
        for (int i = 1; i <= n; i++)
        {
            if (a[i] == 0)
            {
                if (v[i] > V)
                {
                    for (int j = 1; j <= m; j++)
                    {
                        if (p[i] >= st[i] && p[i] <= L)
                        {
                            cnt[i].push_back(i);
                            s[i].w++;
                        }
                    }
                }
            }
            else
            {
                int ed = (V * V - v[i] * v[i]) / (2 * a[i]) + (v[i] > 0 ? 1 : 0);
                if (ed < 0)
                {
                    sum--;
                    continue;
                }
                else if (ed == 0)
                {
                    if (mp[ed])
                    {
                        cnt[mp[ed]].push_back(i);
                        s[i].w++;
                    }
                    else
                    {
                        sum--;
                    }
                    continue;
                }
                for (int j = 1; j <= m; j++)
                {
                    if (p[i] >= st[i] && p[i] <= L)
                    {
                        cnt[i].push_back(i);
                        s[i].w++;
                    }
                }
            }
        }
        sort(s+1,s+m+1,cmp);
        for(int i=1;i<=m;i++){
            bool flag=0;
            for(int i=0;i<cnt[s[i].id].size();i++){
                if(!cat[cnt[s[i].id][i]]){
                    flag=1;
                    sum--;
                    cat[cnt[s[i].id][i]]=1;
                }
                if(sum==0)break;
            }
            if(flag)ans++;
            if(sum==0){
                cout<<m-ans<<endl;
            }
        }
        cout<<m<<endl;
        sum=n;
        ans=0;
    }
    return 0;
}